package com.c2rusthub.service.mapper;

import com.c2rusthub.service.model.TaskClaimed;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface TaskClaimedMapper {

    List<TaskClaimed> findClaimedTasksByTaskId(int taskId);

    TaskClaimed findClaimedTasksById(int Id);


    // 更新任务的状态为已完成 (progress = 1)
    @Update("UPDATE t_task_claimed SET progress = '1' WHERE id = #{taskClaimedId}")
    int updateTaskProgressToCompleted(int taskClaimedId);


    /**
     * 插入已领转译任务记录
     *
     * @param taskClaimed 任务领取信息
     */
    @Insert("INSERT INTO t_task_claimed (task_id, claim_user_id, rust_url, readme_detail, progress, created_time) " +
            "VALUES (#{taskId}, #{claimUserId}, #{rustUrl}, #{readmeDetail}, #{progress}, now())")
    void insertTaskClaimed(TaskClaimed taskClaimed);

    /**
     * 更新已认领任务的信息
     *
     * @param taskClaimed 任务信息
     */
    @Update("UPDATE t_task_claimed SET rust_url = #{rustUrl}, readme_detail = #{readmeDetail}, progress = #{progress}, updated_time = now() " +
            "WHERE id = #{id}")
    void updateTaskClaimed(TaskClaimed taskClaimed);
}
